package com.service.impl;

import com.dao.FilmMapper;
import com.dao.PlayMapper;
import com.dao.SoonMapper;
import com.entity.Film;
import com.entity.Play;
import com.entity.Soon;
import com.service.IndexService;
import com.vo.FilmDetailVO;
import com.vo.FilmVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    private FilmMapper filmMapper;
    @Autowired
    private SoonMapper soonMapper;
    @Autowired
    private PlayMapper playMapper;

    @Override
    public List<FilmDetailVO> selectTop() {
            List<Film> films = filmMapper.selectTop();
            List<FilmDetailVO> returns = new ArrayList<>();
            for(Film f : films){
                FilmDetailVO ff = new FilmDetailVO();
                BeanUtils.copyProperties(f, ff);
                List<Play> plays =playMapper.selectByFilmId(f.getF_id());

                returns.add(ff);
            }
        return returns;
    }

    @Override
    public List<FilmDetailVO> selectSoon() {
        List<Soon> films = soonMapper.selectAll();
        List<FilmDetailVO> returns = new ArrayList<>();
        for(Soon f : films){
            FilmDetailVO ff = new FilmDetailVO();
            ff.setF_id(f.getfId());
            ff.setF_name(f.getName());
            ff.setF_director(f.getDirector());
            ff.setF_players(f.getPlayer());
            ff.setF_type(f.getType());
            ff.setF_country(f.getCountry());
            ff.setF_length(f.getLength());
            ff.setF_synopsis(f.getSynopsis());
            ff.setF_time(f.getPlayTime());
            ff.setImg_path(f.getImgPath());
            returns.add(ff);
        }
        return returns;
    }

    @Override
    public FilmDetailVO filmDetail(String filmId) {
        Soon f = soonMapper.filmDetail(filmId);
        FilmDetailVO ff = new FilmDetailVO();
        ff.setF_id(f.getfId());
        ff.setF_name(f.getName());
        ff.setF_director(f.getDirector());
        ff.setF_players(f.getPlayer());
        ff.setF_type(f.getType());
        ff.setF_country(f.getCountry());
        ff.setF_length(f.getLength());
        ff.setF_synopsis(f.getSynopsis());
        ff.setF_time(f.getPlayTime());
        ff.setImg_path(f.getImgPath());
        return ff;
    }

}
